# -*- coding: utf-8 -*-
"""
@Time ： 2020/10/30 16:12
@Auth ： Mr. JJ_Cloud
@Company ：testingedu.com.cn
@Function ：修改文件前加上list.add("，后加上");
"""

import  os

def updateFile(file,str):
    """
    在文件的每一行前面增加关键字
    :param file: 文件名
    :param str: 关键字
    """
    file_data = ""
    with open(file,"r") as f :
        for line in f:
            line = str + line
            file_data += line
    with open(file,"w") as f :
        f.write(file_data)

base_dir = "D:\\Test\\"
str = 'list.add("'
for file_name in os.listdir(base_dir):
    file_name = os.path.join(base_dir,file_name)
    print(file_name)
    updateFile(file_name,str)


file = open("D:\\Test\\before.txt","r",newline='\r\n')
newfile = open("D:\\Test\\after.txt",'w',)

while True:
    lines = file.readlines()
    if not lines:
       break
    for line in lines:
        newfile.write(line.replace('\r\n',u'");\r\n'))

file.close()
newfile.close()









